home *** CD-ROM | disk | FTP | other *** search
- #define C
-
- #undef PROFILE
- #define COUNT
-
- #include "view.h"
- #include "trig.h"
-
- #ifdef __GNUC__
- #include <osbind.h>
- #include <memory.h>
- #else
- #include <tos.h>
- #endif
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- #define SKY_COLOR 1
- #define FLOOR_COLOR 2
- #define WALL_COLOR 3
- #define RED_COLOR 4
- #define LEDGE_COLOR 5
- #define ZMIN 20L
-
- #define UPPER_TYPE 0
- #define WALL_TYPE 1
- #define LOWER_TYPE 2
-
- #ifdef C
- void DrawNode(short node_num);
- void DrawSegs(void);
- #endif
-
- short width = 320;
- short height = 200;
- short scale = 1;
-
- short flooropt = 0;
- short floorcol = 0;
- short nofloor = 0;
- short wallopt = 0;
- short wallcol = 0;
- short singlestep = 0;
- short showdata = 0;
- short draw_2D = 0;
- short chksect = 1;
- short tellsect = 0;
-
- #ifdef COUNT
- long drawview;
-
- long addfloor;
- long addfloor_loops;
-
- long addwall;
- long addwall_loops;
-
- long coldraw;
- long coldraw_loops;
-
- long rowdraw;
- long rowdraw_loops;
-
- long drawnode;
- long drawssector;
- long drawssector_loops;
- long loadseg;
- long loadseg_loops1;
- long loadseg_loops2;
-
- long setuptime;
- long drawtime;
- long c2ptime;
- #endif
-
- /* These are some yucky global variables. They should probably
- * be moved into the class's member data.
- */
- short ColCount;
- short WallCount;
- short WallRunCount;
- short FirstSSector;
-
- extern short MaxNode;
-
- /* Elements of this array indicate if a screen column is completely drawn. */
-
- #if 0
- short Col_Done[320];
- #endif
- char Col_Done[320]; /* Slightly better for the cache */
-
-
- /* Elements of this array hold indexes into the wall_run array. */
-
- #if 1
- short intersections[50][320];
- #endif
-
- /* The number of wall_runs visible on a particular screen column. */
-
- #if 1
- short int_count[320];
- #endif
-
- /* MaxY & MinY are the active edge lists for the top & bottom of the screen. */
-
- short MaxY[320];
- short MinY[320];
-
-
- /* This is the wall_run array. It contains all of the wall_runs which
- * are visible in a single frame.
- */
-
- #if 1
- wall_run walls[8000]; /* 320*50 = 16000 */
- #endif
-
- short walltop[320];
- short wallbottom[320];
-
- /* The next two arrays are used for both floors and ceilings.
- * Elements of this array hold indexes into the floor_run array.
- */
-
- #if 1
- floor_run floorlist[200][40];
- #endif
-
- short floorlst[200];
- short floortex[200];
-
- /* The number of floor_runs visible on a particular screen column. */
-
- short runcount[200];
-
-
- /* The offscreen buffer. */
- char *screenbuf;
-
-
- extern void c2p(char *buf, int w_area, int h_area);
- extern long get_timer(void);
-
-
- /* This is the constructor for the View. */
-
- void ViewSetup(void)
- {
- #ifdef COUNT
- drawview = 0;
- addfloor = 0;
- addfloor_loops = 0;
- addwall = 0;
- addwall_loops = 0;
- coldraw = 0;
- coldraw_loops = 0;
- rowdraw = 0;
- rowdraw_loops = 0;
- drawnode = 0;
- drawssector = 0;
- drawssector_loops = 0;
- loadseg = 0;
- loadseg_loops1 = 0;
- loadseg_loops2 = 0;
- setuptime = 0;
- drawtime = 0;
- c2ptime = 0;
- #endif
-
- Seg_Array = 0;
- Side_Array = 0;
- Line_Array = 0;
- Node_Array = 0;
- PNode_Array = 0;
- Sector_Array = 0;
- Vertex_Array = 0;
- SSector_Array = 0;
- Blockmap_Array = 0;
- Blockmap_Header = 0;
-
- if ((screenbuf = malloc(64000L * sizeof(char))) == NULL)
- exit(-1);
- }
-
-
- /* The destructor deletes all of the dynamically allocated memory. */
-
- void ViewRemove(void)
- {
- #ifdef COUNT
- printf("\nDrawview: %ld\n", drawview);
- printf("Addfloor: %ld %ld\n", addfloor / drawview, addfloor_loops / drawview);
- printf("Addwall: %ld %ld\n", addwall / drawview, addwall_loops / drawview);
- printf("Coldraw: %ld %ld\n", coldraw / drawview, coldraw_loops / drawview);
- printf("Rowdraw: %ld %ld\n", rowdraw / drawview, rowdraw_loops / drawview);
- printf("Drawnode: %ld\n", drawnode / drawview);
- printf("Drawssector: %ld %ld\n", drawssector / drawview, drawssector_loops / drawview);
- printf("Loadseg: %ld %ld %ld\n", loadseg / drawview, loadseg_loops1 / drawview, loadseg_loops2 / drawview);
- printf("Setup time: %ld\n", setuptime / drawview);
- printf("Draw time: %ld\n", drawtime / drawview);
- printf("C2p time: %ld\n", c2ptime / drawview);
- #endif
-
- free(Seg_Array);
- free(Side_Array);
- free(Line_Array);
- free(Node_Array);
- free(PNode_Array);
- free(Sector_Array);
- free(Vertex_Array);
- free(SSector_Array);
- free(Blockmap_Array);
-
- free(screenbuf);
- }
-
-
- /* This is the main drawing function. */
-
- void DrawView(void)
- {
- short i;
- long starttime;
-
- /* Initialize housekeeping variable for each frame. */
-
- ColCount = 0;
- WallCount = 0;
- #if 1
- WallRunCount = 0;
- #endif
- FirstSSector = 1;
-
- #ifdef COUNT
- drawview++;
- #endif
- #ifdef PROFILE
- addfloor = 0;
- addfloor_loops = 0;
- addwall = 0;
- addwall_loops = 0;
- coldraw = 0;
- coldraw_loops = 0;
- rowdraw = 0;
- rowdraw_loops = 0;
- drawnode = 0;
- drawssector = 0;
- drawssector_loops = 0;
- loadseg = 0;
- loadseg_loops1 = 0;
- loadseg_loops2 = 0;
- setuptime = 0;
- drawtime = 0;
- c2ptime = 0;
- #endif
-
- for(i = 0;i < width;i++) {
- #if 0
- Col_Done[i] = 0; /* No columns have been drawn. */
- int_count[i] = 0; /* No walls have been drawn. */
- MinY[i] = 0; /* Min y value is 0. */
- #endif
- MaxY[i] = height; /* Max y value is 'height' (was 200). */
- }
-
- memset(Col_Done, 0, width * sizeof(char));
- #if 1
- memset(int_count, 0, width * sizeof(short));
- #endif
- memset(MinY, 0, width * sizeof(short));
-
- #if 1
- for (i = 0;i < height;i++) { /* No floors or ceilings have been drawn. */
- #if 0
- runcount[i] = 0;
- #endif
- floorlist[i][0].end = 0;
- floorlist[i][0].start = width;
- floorlst[i] = -1;
- }
- #endif
-
- memset(runcount, 0, height * sizeof(short));
-
- /* This is the recursive function.
- * It can probably be rewritten to use data recursion.
- */
-
- #ifdef COUNT
- starttime = get_timer();
- #endif
-
- if ((nofloor && !flooropt) || singlestep || draw_2D)
- memset(screenbuf, 0, (long)width * height);
-
- DrawNode(MaxNode);
- #ifdef COUNT
- setuptime += get_timer() - starttime;
- #endif
-
- /* Draw all of the wall_runs and floor_runs onto the offscreen buffer. */
-
- if (!draw_2D) {
- #ifdef COUNT
- starttime = get_timer();
- #endif
- DrawSegs();
- #ifdef COUNT
- drawtime += get_timer() - starttime;
- #endif
- }
-
- singlestep = 0;
-
- /* Blast the offscreen buffer to display memory. */
-
- #ifdef COUNT
- starttime = get_timer();
- #endif
- c2p(screenbuf, width, height);
- #ifdef COUNT
- c2ptime += get_timer() - starttime;
- #endif
-
- #ifdef PROFILE
- printf("Addfloor: %ld %ld\n", addfloor, addfloor_loops);
- printf("Addwall: %ld %ld\n", addwall, addwall_loops);
- printf("Coldraw: %ld %ld\n", coldraw, coldraw_loops);
- printf("Rowdraw: %ld %ld\n", rowdraw, rowdraw_loops);
- printf("Drawnode: %ld\n", drawnode);
- printf("Drawssector: %ld %ld\n", drawssector, drawssector_loops);
- printf("Loadseg: %ld %ld %ld\n", loadseg, loadseg_loops1, loadseg_loops2);
- printf("Setup time: %ld\n", setuptime / drawview);
- printf("Draw time: %ld\n", drawtime / drawview);
- printf("C2p time: %ld\n", c2ptime / drawview);
- #endif
- }
-